import java.util.Scanner;

public class Text {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            int[] array = new int[a];
            for(int i = 0;i < a;i++) {
                array[i] = in.nextInt();
            }
            int max = array[0];
            int sum = array[0];
            for(int i = 1;i < array.length;i++) {
                sum = Math.max(sum+array[i],array[i]);
                if(sum > max) {
                    max = sum;
                }
            }
            System.out.println(max);
        }
    }
}
